/*OWmq6Ugo6jPE4W7xoi1UXlXa6Uo/GAeDS7JN8mWOERFI1YSIxjzhvlCZGmRoUoRn*/
import { ajax } from 'nc-lightapp-front';
import { cytjCode, hxgzCode, bfCode, dfCode, publicCode,Copyform } from '../constants';
import { setAllFieldEditable, setFieldDisabledAP } from '../../../public/publicMethods/pubUtils.js';
import { jf_hxdxCBox_AfterEvent, jfBillTypeBox_AfterEvent, df_hxdxCBox_AfterEvent } from '../../../public/publicMethods/pubAfterEventAP.js';
import {copyFormPkorgAfterEvent}from '../../../public/publicMethods/pubAfterEvent.js';

export default function afterEvent(props, moduleId, key, value, oldValue) {
	// props, moduleId(区域id), key(操作的键), value（当前值），oldValue(旧值)

	//常用条件编辑后事件
	if (moduleId == cytjCode) {
		if (key == 'pk_org' && value.value != null && value.value != "") {
			//设置常用条件所有字段可编辑
			let arr = [cytjCode, bfCode, dfCode, publicCode]
			setAllFieldEditable(props, cytjCode, arr, true);
			if (this.editflag) {
				//设置方案名称不可编辑
				props.form.setFormItemsDisabled(cytjCode, { name: true });
			}
			setOrgLocalCurrPK(props, key, value);
			props.form.setFormItemsRequired(hxgzCode, { 'jefxCmbBox': false })
		}

		// 本方核销对象
		if (key == 'jf_hxdxCBox') {
			jf_hxdxCBox_AfterEvent(this, props, value, cytjCode, bfCode, dfCode);
		}

		//本方单据类型
		if (key == 'jfBillTypeBox') {
			jfBillTypeBox_AfterEvent(this, props, value, cytjCode, bfCode, dfCode);
		}

		// 对方核销对象
		if (key == 'df_hxdxCBox') {
			df_hxdxCBox_AfterEvent(this, props, value, cytjCode, bfCode, dfCode);
		}

		//根据数据控制字段可编辑性
		setFieldDisabledAP(props, cytjCode)
	}

	//核销规则编辑后事件
	if (moduleId == hxgzCode) {
		//红蓝对冲
		if (key == 'hldcChkBox') {
			if (value.value == true) {
				props.form.setFormItemsRequired(hxgzCode, { 'jefxCmbBox': false })
				props.form.setFormItemsDisabled(hxgzCode, { jefxCmbBox: true });
				props.form.setFormItemsValue(hxgzCode, { 'jefxCmbBox': { value: null, display: null } });
			} else {
				props.form.setFormItemsRequired(hxgzCode, { 'jefxCmbBox': true })
				props.form.setFormItemsDisabled(hxgzCode, { jefxCmbBox: false });
				props.form.setFormItemsValue(hxgzCode, { 'jefxCmbBox': { value: 0, display: this.state.json['verificationsheet-000025'] } });/* 国际化处理： 正*/
			}
		}
	}
	if(moduleId==Copyform){
        copyFormPkorgAfterEvent(this,props,key,value);
	}

}

//根据组织设置默认核销币种
function setOrgLocalCurrPK(props, key, value) {
	if (key == 'pk_org') {
		if (value == null || value.value == null) {
			props.form.setFormItemsValue(hxgzCode, { 'hxbzRef': { value: null, display: null } });
		} else {
			ajax({
				url: '/nccloud/arap/verifyfa/afterEvent.do',
				data: {
					key: key,
					value: value.value
				},
				success: (res) => {
					if (res.success) {
						if (res.data) {
							props.form.setFormItemsValue(hxgzCode, { 'hxbzRef': { value: res.data.value, display: res.data.name } });
						}
					}
				}
			});
		}
	}

}

/*OWmq6Ugo6jPE4W7xoi1UXlXa6Uo/GAeDS7JN8mWOERFI1YSIxjzhvlCZGmRoUoRn*/